package org.example.util;


import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.example.bean.Cord;
import org.example.bean.JsonGamePos;
import java.util.List;


public class MapUtil {
    private static final Logger logger = LogManager.getLogger(MapUtil.class);

    /**
     * 获取路径总长度
     * @return
     */
    public static double getDisSum(List<JsonGamePos> pathPosList){
        double dis = 0;
        for (int i = 0; i < pathPosList.size() - 1 ; i++) {
            JsonGamePos gamePos1 = pathPosList.get(i);
            JsonGamePos gamePos2 = pathPosList.get(i+1);
            dis += getDistance(gamePos1, gamePos2);
        }
        return dis;
    }

    /**
     * 获取2点之间的距离
     * @param p1
     * @param p2
     * @return
     */
    public static double getDistance(JsonGamePos p1, JsonGamePos p2) {
        return Math.sqrt((p2.getX() - p1.getX()) * (p2.getX() - p1.getX()) + (p2.getY() - p1.getY()) * (p2.getY() - p1.getY()) + (p2.getZ() - p1.getZ()) * (p2.getZ() - p1.getZ()));
    }

    /**
     * 获取2点之间的距离
     * @param p1
     * @param p2
     * @return
     */
    public static double getDistance(Cord p1, Cord p2) {
        return Math.sqrt((p2.getX() - p1.getX()) * (p2.getX() - p1.getX()) + (p2.getY() - p1.getY()) * (p2.getY() - p1.getY()));
    }



}
